
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	request.setAttribute("path", path);
	String pk = request.getParameter("pk");
		if(StringUtils.isEmpty(pk)){
		pk = "";
	} 
	String thispage = request.getParameter("page");
	if(StringUtils.isEmpty(thispage)){
		thispage = "1";
	}
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <meta name="keyword" content="">
    <link rel="shortcut icon" href="img/favicon.png">

    <title>
    <%
			if (StringUtils.isEmpty(pk)) {
				out.print( "新增角色信息" );
			} else {
				out.print( "修改角色信息" );
			}
		%>
	</title>

    <!-- Bootstrap core CSS -->
    <link href="${path}/style/def/css/bootstrap.min.css" rel="stylesheet">
    <link href="${path}/style/def/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="${path}/style/authory/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="${path}/style/def/css/style.css" rel="stylesheet">
    <link href="${path}/style/def/css/style-responsive.css" rel="stylesheet" />
    
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="${path}js/html5shiv.js"></script>
      <script src="${path}js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
      <!--main content start-->
          <section class="wrapper">
              <!-- page start-->
              <div class="row">
                  <div class="col-lg-12">
                      <section class="panel">
                          <header class="panel-heading">
                            	 <%
									if (StringUtils.isEmpty(pk)) {
										out.print( "新增角色信息" );
									} else {
										out.print( "修改角色信息" );
									}
								%>
                          </header>
                          <div class="panel-body">
                              <div class="form">
                                  <form class="cmxform form-horizontal tasi-form" id="roleForm" method="post" action="">
                                          <input id="id" name="id" type="hidden"/>
                                         
                                  	   <div class="form-group col-lg-6">
                                          <label for="firstname" class="control-label col-sm-2">角色名：</label>
											  <div class="col-sm-10">
											  	 <input class=" form-control" id="name" name="name" type="text"/>
											  </div>
                                      </div>
                                      
                                     <div class="form-group col-lg-6">
                                          <label for="firstname" class="control-label col-sm-2">描述：</label>
											  <div class="col-sm-10">
											  	 <input class=" form-control" id="description" name="description" type="text"/>
											  </div>
                                      </div>
                                       
                                      <div class="form-group">
                                          <div class="col-lg-offset-2 col-lg-12">
                                              <button class="btn btn-danger" type="button" onclick="ajaxSubmitForm()">保存</button> 
                                              <button class="btn btn-default" type="button" onclick="javascript:window.location.href='${path}/jsp/role/role_list.jsp?page=<%=thispage%>'">取消</button>
                                          </div>
                                      </div>
                                  </form>
                              </div>
                          </div>
                      </section>
                  </div>
              </div>
              <!-- page end-->
          </section>
      <!--main content end-->
     

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="${path}/style/authory/js/jquery.js"></script>
    <script src="${path}/style/def/js/bootstrap.min.js"></script>
    <script class="include" type="text/javascript" src="${path}//style/authory/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="${path}/style/authory/js/jquery.scrollTo.min.js"></script>
    <script src="${path}/style/authory/js/bootbox.min.js"></script>
    <script src="${path}//style/def/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script type="text/javascript" src="${path}/style/def/js/jquery.validate.min.js"></script>
     <script type="text/javascript" src="${path}/style/def/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
    <script src="${path}/style/def/js/respond.min.js" ></script>
	<script src="${path}/style/authory/js/common.js"></script>
    <!--common script for all pages-->
    <script src="${path}/style/authory/js/common-scripts.js"></script>

    <!--script for this page-->
  <%--   <script src="${path}/js/form-validation-script.js"></script>
   --%>   
	<script type="text/javascript">
	var pk = '<%=pk%>';
      jQuery.component({
      });
	
	function gotoList(){
		window.location.href = "${path}/jsp/role/role_list.jsp";
	}
	
	function insertUser(){
		jQuery.ajax({
			url : "${path}/roleMng/insertRole.do",
			type : "get",
			data : $("#roleForm").serialize(),
			success : function(result) { 
				if (result == 'success') {
					bootbox.alert({message:"保存成功！",callback:function(){
						gotoList();
  					}});
				} else {
					bootbox.alert( '保存失败'); 
				}
			},
			error : function(result) {
				bootbox.alert('保存失败:'+result); 
			}

		});
	}
	
	function updateUser(){
		jQuery.ajax({
			url : "${path}/roleMng/updateRole.do",
			type : "post",
			data : $("#roleForm").serialize(),
			success : function(result) {
				if (result == 'success') {
					bootbox.alert({message:"保存成功！",callback:function(){
						gotoList();
  					}});
				} else {
					bootbox.alert('保存失败'); 
				}
			},
			error : function(result) {
				bootbox.alert('保存失败'); 
			}
		});
	}
	
	  
	function ajaxSubmitForm(){
		if (pk == "") {
			insertUser();
		} else {
			updateUser();
		}
	}
	
	$(function(){
		 
		if(pk!=''){
			jQuery.ajax({
				url : "${path}/roleMng/getDetailByPk.do",
				type : "post",
				data : {pk:pk},
				success : function(result) {
					if(result=='undefined'){
						return;
					}
					$("input[name='id']").val(result.id);   
					$("input[name='name']").val(result.name);
					$("input[name='description']").val(result.description);
				},
				error : function(result) {
					
				}
			});
		}
	});
	
	</script>
  </body>
</html>
